package com.qire.manhua.dal;

import com.qire.antsbinder.dal.DataWarehouse.MethodType;
import com.qire.antsbinder.dal.DataWarehouse.WarehouseCacheMode;
import com.qire.antsbinder.dal.annotation.DataAccess;
import com.qire.antsbinder.dal.annotation.ParamsAlias;
import com.qire.common.constant.Url;
import com.qire.manhua.dal.converter.BatchChapterIdsConverter;
import com.qire.manhua.dal.converter.BatchDelFavoriteConverter;
import com.qire.manhua.dal.converter.EnablePreferencesConverter;
import com.qire.manhua.model.vo.BatchBuyChaptersPriceVO;
import com.qire.manhua.model.vo.BatchDownloaderInfoVO;
import com.qire.manhua.model.vo.BookshelfFavoriteItemVO;
import com.qire.manhua.model.vo.BookshelfRecommendVO;
import com.qire.manhua.model.vo.ChaptersBulletScreenVO;
import com.qire.manhua.model.vo.ChaptersResultsVO;
import com.qire.manhua.model.vo.ClassifiedComicVO;
import com.qire.manhua.model.vo.CollectTaskVO;
import com.qire.manhua.model.vo.ComicDetailVO;
import com.qire.manhua.model.vo.ComicQuickReadInfoVO;
import com.qire.manhua.model.vo.ComicRankListOfHotVO;
import com.qire.manhua.model.vo.ComicRankListOfVipVO;
import com.qire.manhua.model.vo.ComicReadFinishPushVO;
import com.qire.manhua.model.vo.ComicReadHistoryVO;
import com.qire.manhua.model.vo.DirectoryVO;
import com.qire.manhua.model.vo.SearchWordsVO;
import com.qire.manhua.model.vo.RandomRecommendVO;
import com.qire.manhua.model.vo.OkResponseVO;
import com.qire.manhua.model.vo.SearchResultVO;
import com.qire.manhua.model.vo.TaskStateResponseVO;

import java.util.List;

/**
 * 漫画数据访问
 */
public interface IComicDataDAL {
    // 缓存失效时间
    long CACHE_TIME_10_DAY = 1000L * 60 * 60 * 24 * 10;

    //region #阅读记录相关

    /**
     * 同步上传本地阅读记录
     * @param comicIdList
     * @return
     */
    @DataAccess(url = Url.my_sync_read, methodType = MethodType.GET)
    OkResponseVO uploadReadHistoryRecord(@ParamsAlias(name = "reads", converter = BatchDelFavoriteConverter.class) List<String> comicIdList);

    /**
     * 同步拉取服务器阅读记录
     * @param pageNo 页号，默认写0获取全部
     * @return
     */
    @DataAccess(url = Url.HomeBookshelfHistoryComicList, methodType = MethodType.GET)
    List<ComicReadHistoryVO> fetchReadHistoryRecord(@ParamsAlias(name = "page") int pageNo);

    /**
     * 同步删除服务器阅读记录
     * @param comicIdList
     * @return
     */
    @DataAccess(url = Url.my_user_read_delete, methodType = MethodType.GET)
    OkResponseVO removeReadHistoryRecord(@ParamsAlias(name = "reads", converter = BatchDelFavoriteConverter.class) List<String> comicIdList);

    //endregion #阅读记录相关 end

    //region #书架相关

    /**
     * @return 获取书架收藏推荐banner位漫画列表
     */
    @DataAccess(url = Url.shelf_recomm, methodType = MethodType.GET)
    BookshelfRecommendVO fetchBookshelfRecommendList();

//    WarehouseCacheMode cacheMode = isUpdate ? WarehouseCacheMode.REQUEST_FAILED_READ_CACHE : WarehouseCacheMode.FIRST_CACHE_THEN_REQUEST;
    /**
     * 获取收藏夹列表数据
     * @param pageNo 页号，使用0，获取全部
     * @return
     */
    @DataAccess(url = Url.HomeBookshelfFavoritesComicList, methodType = MethodType.GET)
    List<BookshelfFavoriteItemVO> fetchFavoritesList(@ParamsAlias(name = "page") int pageNo);

    /**
     * 批量删除收藏夹中漫画
     * @param comicIdList 漫画ID列表，世界接口需要一个JSON格式的ID与书籍类型包装，使用转换器 {@link BatchDelFavoriteConverter} 所以只需要传递ID列表
     * @return
     */
    @DataAccess(url = Url.my_user_shelf_delete, methodType = MethodType.GET)
    OkResponseVO batchDelFavoritesList(@ParamsAlias(name = "reads", converter = BatchDelFavoriteConverter.class) List<String> comicIdList);

    /**
     * 添加/取消收藏到书架
     * @param bookId    漫画书ID
     * @param bookType  书类型:之前存在小说类型，现在已经取消掉了，固默认固定值0 */
    @DataAccess(url = Url.whetherJoinMyBookshelf, methodType = MethodType.GET)
    CollectTaskVO whetherJoinMyBookshelf(@ParamsAlias(name = "book_id") int bookId, @ParamsAlias(name = "btype") int bookType);

    //endregion #书架相关 end

    //region #漫画阅读相关

    /**
     * 点赞喜欢的章节
     * @param comicId 漫画ID
     * @param chapterId 章节ID
     * @return
     */
    @DataAccess(url = Url.ChapterGiveLike)
    OkResponseVO giveLike(@ParamsAlias(name = "book_id") int comicId, @ParamsAlias(name = "chapter_id") int chapterId);

    /**
     * 获取快速阅读章节信息
     * @param bookId    漫画书ID */
    @DataAccess(url = Url.ComicQuickReadData, methodType = MethodType.GET, cacheMode = WarehouseCacheMode.FIRST_CACHE_THEN_REQUEST)
    ComicQuickReadInfoVO fetchComicQuickReadInfo(@ParamsAlias(name = "book_id") int bookId);

    /**
     * 获取阅读最后一章结束推送信息
     * @param bookId
     * @return
     */
    @DataAccess(url = Url.ComicReadFinishPush, methodType = MethodType.GET, cacheMode = WarehouseCacheMode.FIRST_CACHE_THEN_REQUEST)
    ComicReadFinishPushVO fetchComicReadFinishPush(@ParamsAlias(name = "book_id") int bookId);

    /**
     * 通过漫画书ID获取漫画书详情信息
     * @param bookId 漫画书ID
     * */
    @DataAccess(url = Url.comicBookDetail, methodType = MethodType.GET, cacheMode = WarehouseCacheMode.FIRST_CACHE_THEN_REQUEST, cacheTime = CACHE_TIME_10_DAY)
    ComicDetailVO fetchComicDetailData(@ParamsAlias(name = "book_id") int bookId);

    /**
     * 获取漫画目录信息
     * @param bookId    漫画书ID */
    @DataAccess(url = Url.comicDirectoryInfo, methodType = MethodType.GET)
    DirectoryVO fetchComicDirectoryInfo(@ParamsAlias(name = "book_id") int bookId);

    /**
     * 预加载漫画章节详情信息
     * @param bookId    漫画书ID
     * @param chapterId 章节ID */
    @DataAccess(url = Url.PreInstallComicChaptersInfo, methodType = MethodType.GET)
    ChaptersResultsVO fetchPreInstallComicChaptersInfo(@ParamsAlias(name = "book_id") int bookId, @ParamsAlias(name = "chapter_id") int chapterId);

    /**
     * 获取漫画章节详情信息
     * @param bookId    漫画书ID
     * @param chapterId 章节ID */
    @DataAccess(url = Url.comicChaptersInfo, methodType = MethodType.GET)
    ChaptersResultsVO fetchComicChaptersInfo(@ParamsAlias(name = "book_id") int bookId, @ParamsAlias(name = "chapter_id") int chapterId);

    /**
     * 阅读历史
     * @param bookId
     * @param chapterId
     * @return
     */
    @DataAccess(url = Url.UpdateReadHistory, methodType = MethodType.GET)
    OkResponseVO updateReadHistory(@ParamsAlias(name = "book_id") int bookId, @ParamsAlias(name = "chapter_id") int chapterId);

    /**
     * 获取漫画弹幕信息通过漫画ID及章节ID
     * @param bookId    漫画书ID
     * @param chapterId 章节ID */
    @DataAccess(url = Url.v5_comicBulletScreen_Fetch, methodType = MethodType.GET)
    ChaptersBulletScreenVO fetchComicBulletScreen(@ParamsAlias(name = "bookId") int bookId, @ParamsAlias(name = "chapterId") int chapterId);

    /**
     * 提交添加弹幕
     * @param bookId    漫画ID
     * @param chapterId 章节ID
     * @param x 弹幕X坐标，转换为相对百分比后的值
     * @param y 弹幕Y坐标，转换为相对百分比后的值
     * @param bulletContent 弹幕内容
     * @param bulletColorTag 弹幕颜色标签
     * @param fontSizeNumber 弹幕字体大小字号
     * @param imgUrl    所属图片路径
     * @return
     */
    @DataAccess(url = Url.v5_comicBulletScreen_Add)
    TaskStateResponseVO addComicBulletScreen(@ParamsAlias(name = "bookId") int bookId, @ParamsAlias(name = "chapterId") int chapterId,
                                             @ParamsAlias(name = "xpos") String x, @ParamsAlias(name = "ypos") String y,
                                             @ParamsAlias(name = "roastContent") String bulletContent, @ParamsAlias(name = "color") String bulletColorTag,
                                             @ParamsAlias(name = "font_size") int fontSizeNumber, @ParamsAlias(name = "img") String imgUrl);

    /**
     * 解锁章节通过购买
     * @param comicId   漫画ID
     * @param chapterId 章节ID
     * @param chapterPrice  章节价格
     * @param paymentType   支付方式: "bean" 或者 "coin"
     * @param autoPay   自动解锁状态
     * @return
     */
    @DataAccess(url = Url.ComicChapterUnlockByBuy)
    OkResponseVO unlockChapterByBuy(@ParamsAlias(name = "book_id") int comicId, @ParamsAlias(name = "chapter_id") int chapterId,
                                    @ParamsAlias(name = "chapter_price") String chapterPrice, @ParamsAlias(name = "buy_type") String paymentType,
                                    @ParamsAlias(name = "auto_pay") int autoPay);

    /**
     * 解锁章节通过广告
     * @param comicId   漫画ID
     * @param chapterId 章节ID
     * @return
     */
    @DataAccess(url = Url.ComicChapterUnlockByAd)
    OkResponseVO unlockChapterByAdvert(@ParamsAlias(name = "book_id") int comicId, @ParamsAlias(name = "chapter_id") int chapterId);

    /**
     * 人气上报接口
     * @param bookId 书籍ID
     * @param chapterId 章节ID
     * @param scrollCount 滚动屏幕书，屏幕高度定长滚动数以当前漫画阅读位置除以屏定长屏幕高度得到所在第几屏
     * @param screenHeight 定长屏幕高度
     * @param comicHeight 漫画总高度
     * @return
     */
    @DataAccess(url = Url.v4_comicPopular, methodType = MethodType.GET)
    OkResponseVO reportComicPopular(@ParamsAlias(name = "book_id") int bookId, @ParamsAlias(name = "book_id") int chapterId,
                                    @ParamsAlias(name = "book_id") int scrollCount, @ParamsAlias(name = "book_id") int screenHeight,
                                    @ParamsAlias(name = "book_id") int comicHeight);

    //endregion #漫画阅读相关 end

    //region #漫画查找推荐相关

    /**
     * 通过漫画书ID随机推荐相关类型漫画
     * @param bookId 漫画ID
     */
    @DataAccess(url = Url.comicBookDetailCommend, methodType = MethodType.GET,cacheMode = WarehouseCacheMode.REQUEST_FAILED_READ_CACHE, cacheTime = CACHE_TIME_10_DAY)
    List<RandomRecommendVO> fetchRandomRecommend(@ParamsAlias(name = "book_id") int bookId,
                                                 @ParamsAlias(name = "user_privacy", converter = EnablePreferencesConverter.class) boolean enablePreferences);

    /**
     * 通过指定条件获取分类漫画列表
     * @param classifiedTagId 分类标签ID
     * @param feeType   收费类型
     * @param stateType 连载状态
     * @param sortType  排序方式
     * @param pageNo    页号
     * @return 分类漫画列表
     */
    @DataAccess(url = Url.HomeClassificationComicList, methodType = MethodType.GET)
    List<ClassifiedComicVO> fetchClassifiedComicList(@ParamsAlias(name = "book_type") String classifiedTagId, @ParamsAlias(name = "fee_type") String feeType,
                                                     @ParamsAlias(name = "finish_state") String stateType, @ParamsAlias(name = "sort_type") String sortType,
                                                     @ParamsAlias(name = "page") int pageNo);

    /**
     * 获取漫画搜索热门关键字
     * @return
     */
    @DataAccess(url = Url.book_hot_words, methodType = MethodType.GET, cacheMode = WarehouseCacheMode.REQUEST_FAILED_READ_CACHE)
    List<SearchWordsVO> fetchHotSearchWords();

    /**
     * 获取搜索关键字结果
     * @param searchWords 搜索词
     * @param page 页号 服务器没有实现分页，但要求传递这个字段故保留默认为1
     * @return
     */
    @DataAccess(url = Url.book_search_list_get)
    SearchResultVO fetchSearchResult(@ParamsAlias(name = "search_key") String searchWords, @ParamsAlias(name = "page") int page);

    /**
     * 猜测联想词
     * @return
     */
    @DataAccess(url = Url.book_search_book)
    List<SearchWordsVO> guessAssociativeWords(@ParamsAlias(name = "keys") String searchWords);

    //endregion #漫画查找推荐相关 end

    //region #批量操作

    /**
     * 获取批量购买章节总价
     * @param bookId    漫画书ID
     * @param chapterIds 章节id数组，需要后买解锁的章节ID数组，不包含免费书籍或是自身符合免费条件的书籍
     * @return
     */
    @DataAccess(url = Url.ChapterBuyTotal, methodType = MethodType.GET)
    BatchBuyChaptersPriceVO fetchBatchBuyChaptersPrice(@ParamsAlias(name = "book_id") int bookId,
                                                       @ParamsAlias(name = "chapter_ids", converter = BatchChapterIdsConverter.class) List<String> chapterIds);

    /**
     * 批量购买章节
     * @param bookId    漫画书ID
     * @param chapterIds 章节id数组，需要后买解锁的章节ID数组，不包含免费书籍或是自身符合免费条件的书籍
     * @param totalPrice 购买总价，实际花费价格
     * @return
     */
    @DataAccess(url = Url.ChapterBuyBatch)
    OkResponseVO batchBuyChapters(@ParamsAlias(name = "book_id") int bookId,
                                  @ParamsAlias(name = "chapter_ids", converter = BatchChapterIdsConverter.class) List<String> chapterIds,
                                  @ParamsAlias(name = "total_gold") float totalPrice);

    /**
     * 获取批量下载信息
     * @param bookId    漫画书ID
     * @param chapterIds 章节id数组，包含所有选中需要下载的章节ID，不管是否需要解锁
     * @return
     */
    @DataAccess(url = Url.ChapterDownBatch, methodType = MethodType.GET)
    BatchDownloaderInfoVO fetchBatchDownloaderInfo(@ParamsAlias(name = "book_id") int bookId,
                                                   @ParamsAlias(name = "chapter_ids", converter = BatchChapterIdsConverter.class) List<String> chapterIds);

    //endregion #批量操作 end

    //region #漫画排行榜

    /**
     * 获取综合热门排行榜数据通过根据排行榜类型
     * @param rankType 排行榜类型，有免费榜、畅销榜、新作榜、完结榜，接口使用对应字段 {"free","sell","new","end"}
     * @return
     */
    @DataAccess(url = Url.comicRank)
    ComicRankListOfHotVO fetchComicRankListOfHot(@ParamsAlias(name = "rank_type") String rankType);

    /**
     * 获取VIP人气排行榜数据通过根据排行榜类型
     * @param rankType 排行榜类型，有周榜、月榜、总榜，接口使用对应字段 {"week","month","total"}
     * @return
     */
    @DataAccess(url = Url.v4_vipRanking)
    ComicRankListOfVipVO[] fetchComicRankListOfVip(@ParamsAlias(name = "rank_type") String rankType);

    //endregion #漫画排行榜 end
}
